<template>
    <div>
        <h1>会员等级添加</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">会员等级名称</td>
                    <td><input type="text" v-model="queryInfo.LevelName" /></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="增加" class="btn btn-success"  @click="add" /></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import{reactive,ref} from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';
const router=useRouter();
//声明向后端传递的数据
let queryInfo=reactive({
    LevelName:'',
});

//等级增加
const add=()=>{
    //1.有效性验证 2.发送网络请求向数据库添加数据
    if(queryInfo.LevelName==""){
        alert("等级名称不能为空!");
        return;
    }
    axios({
        url:'https://localhost:7035/api/ZMember',
        method:'post',
        data:queryInfo
    })
    .then(res=>{
        console.log(res);
        if(res.data>0){
            alert("增加成功！");
            router.push("/memberList");
        }
        else if(res.data==-1){
            alert("等级名称重复");
            return;
        }
        else{
            alert("增加失败!");
            return;
        }
    })
    .catch((err)=>{
        console.log(err);
    });
}
</script>

<style scoped>

</style>